package com.bus.service.impl;

import com.bus.dao.CustomerDao;
import com.bus.entity.Customer;
import com.bus.service.CustomerService;
import com.bus.vo.CustomerVo;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Repository;
import org.springframework.stereotype.Service;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

@Service
public class CustomerServiceImpl implements CustomerService {
    @Autowired
    private CustomerDao customerDao;

    @Override
    public Map<String,Object> selectAllCustomer(CustomerVo customerVo) {
        PageHelper.startPage(customerVo.getPage(),customerVo.getLimit());
        List<Customer> customers = customerDao.selectAllCustomer(customerVo);
        PageInfo<Customer> pageInfo = new PageInfo<>(customers);
        long total = pageInfo.getTotal();
        Map<String ,Object> map = new HashMap<>();
        map.put("customers",customers);
        map.put("total",total);
        return map;
    }

    @Override
    public int updateCustomer(CustomerVo customerVo) {
        return customerDao.updateCustomer(customerVo);
    }

    @Override
    public int addCustomer(CustomerVo customerVo) {
        return customerDao.insertCustomer(customerVo);
    }

    @Override
    public int deleteCustomer(CustomerVo customerVo) {
        return customerDao.deleteCustomer(customerVo);
    }
}
